<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .slider {
            width: 500px;
            height: 400px;
            margin: 50px auto;
            overflow: hidden;

            position: relative;
        }

        .btns {
            position: absolute;
            bottom: 10px;

            width: 100%;
            text-align: center;

        }

        .btns a {
            display: inline-block;
            width: 14px;
            height: 14px;
            background-color: #ccc;
            border-radius: 100%;

            /* 让文字消失 */
            text-indent: -9999px;

        }

        .btns a.on {
            background-color: #fff;
            border: 3px solid #ccc;
        }
    </style>
</head>

<body>
    <div class="slider">
        <div class="btns">
            <a href="#" class="on">1</a>
            <a href="#">2</a>
            <a href="#">3</a>
            <a href="#">4</a>
        </div>
        <div class="image">
            <img src="./images/1.jpeg" alt="">
            <img src="./images/2.jpeg" alt="">
            <img src="./images/3.jpeg" alt="">
            <img src="./images/4.jpeg" alt="">
        </div>
    </div>
    <script>
        let btns = document.querySelectorAll('.btns a')
        let img = document.querySelectorAll('.image img')
        btns.forEach(function (v, i) {
            v.onmouseover = function () {
                btns.forEach(function (v2, i2) {
                    v2.className = ''
                })
                // 给自己添加样式
                this.className = 'on'

                // 一刀切,将所有图片影藏
                img.forEach(function (v2, i2) {
                    v2.style.display = 'none'
                });

                // 给按钮对应的图片设置样式
                img[i].style.display = 'block';
            }
        })
    </script>
</body>

</html>